﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes {
    import Engine.Classes.*;
    import flash.events.*;
    import Engine.Transactions.*;
    import Engine.Managers.*;
    import Engine.Interfaces.*;
    import flash.display.*;
    import flash.geom.*;
    import Engine.Helpers.*;
    import Events.*;
    import flash.utils.*;
    import org.aswing.*;
    import Transactions.*;
    import Classes.util.*;
    import Classes.sim.*;
    import __AS3__.vec.*;
    import Classes.effects.*;
    import flash.filters.*;
    import Display.*;
    import GameMode.*;
    import Classes.doobers.*;
    import flash.text.*;
    import Classes.actions.*;
    import Modules.storage.*;
    import Classes.inventory.*;
    import Modules.crew.*;
    import flash.media.*;
    import Display.aswingui.*;
    import Engine.*;
    import Modules.stats.types.*;

    public class MapResource extends ItemInstance implements ICustomToolTipTarget {

        public static const REPLACE_CONTENT:String = "MapResourceEvent:ReplaceContent";
        public static const PLACE_ON_LAND:String = "land";
        public static const PLACE_ON_WATER:String = "water";
        public static const PLACE_ON_LAND_AND_WATER:String = "land_and_water";
        public static const PLACE_ON_ROAD_OR_NEARROAD:String = "road_or_nearroad";

        private static var m_arrowBitmapData:BitmapData;
        private static var m_sellDialogShowing:Boolean = false;
        private static var m_pixelOffset:int = 20;
        private static var m_effectLoader:ImageLoader = null;
        private static var maxZoom:int = Global.gameSettings.getNumber("maxZoom", 4);
        private static var edgeDirtyFilter:DropShadowFilter = new DropShadowFilter(4, 40, 0, 0.8, 8, 8, 3, 1, true);
        private static var dirtyFilter:DropShadowFilter = new DropShadowFilter(4, 40, 0xDDDD00, 0.7, 12, 12, 2, 4, true);

        public const LEFT_SIDE:uint = 1;
        public const RIGHT_SIDE:uint = 2;
        public const BOTTOM_SIDE:uint = 4;
        public const TOP_SIDE:uint = 8;

        private var m_lockRedraw:Boolean = false;
        protected var m_imageClass:ItemImageInstance;
        protected var m_itemImage:DisplayObject;
        protected var m_colorTransform:Number = 0xFFFFFF;
        protected var m_itemOwner:String;
        protected var m_isPendingOrder:Boolean = false;
        protected var m_state:String;
        protected var m_content:DisplayObject;
        protected var m_upgradeActionCount:int = 0;
        protected var m_lastScreenPosition:Point;
        protected var m_dirtyRect:Rectangle;
        protected var m_visitorHighlight:Boolean = false;
        protected var m_scratchBuffer1:BitmapData;
        protected var m_scratchBuffer2:BitmapData;
        protected var m_scratchBufferRect:Rectangle;
        protected var m_scratchBufferRenderContext:RenderContext;
        protected var m_worldRect:Rectangle;
        protected var m_arrowRect:Rectangle;
        protected var m_optFramerate:Boolean = true;
        protected var m_roundRobbinAnim:Boolean = true;
        protected var m_objMat:Matrix;
        protected var m_maskBitmapLoader:Loader;
        protected var m_maskBitmap:Bitmap;
        private var m_effectOverlay:DisplayObject = null;
        protected var m_isSelected:Boolean;
        protected var m_isDragged:Boolean;
        protected var m_color:uint;
        protected var m_roadNotAdjacentEffects:Array;
        protected var m_isRoadVerifiable:Boolean = false;
        protected var m_connectsToRoad:Boolean = false;
        protected var m_dbgServerConnectsToRoad:Boolean = false;
        protected var m_adjRoadFlags:uint = 0;
        public var sideDirectionMap:Dictionary;
        protected var itemImageOffsetX:Number = 0;
        protected var itemImageOffsetY:Number = 0;
        protected var m_statePhase:String = null;
        protected var m_animatedEffects:Array;
        protected var m_ownable:Boolean = false;
        protected var m_storable:Boolean = false;
        protected var m_isShowStateTransition:Boolean = false;
        protected var m_isHighlightable:Boolean = true;
        protected var m_doobersArray:Array;
        protected var m_secureRands:Array;
        protected var m_npcNames:Array = null;
        private var m_SoundClickPlayed:Number = -1;
        private var m_SoundClickDelayTime:Number = -1;
        protected var m_statsName:String;
        protected var m_statsItemName:String;
        protected var m_statsActionNames:Dictionary;
        protected var m_startTime:Number;
        protected var m_stagePickEffect:StagePickEffect;
        protected var m_supplyStorage:SupplyStorage;
        private var m_currentPopulation:int = 0;
        protected var m_npcPopularity:int = 1;
        protected var m_showUpgradeArrow:Boolean = true;
        protected var m_toolTipComponents:Object;
        protected var m_levelProgressComponent:SimpleProgressBar;
        protected var m_alternativeLevelLabel:JLabel;
        protected var m_stringWidthTester:JTextField;
        protected var m_stringWidthThreshold:Number = 0;
        protected var m_active:Boolean;
        protected var m_defaultUpgradeFinish:Function = null;
        protected var m_upgradeActions:UpgradeActions;
        protected var m_isMoveLocked:Boolean = false;
        protected var m_actionQueue:NPCActionQueue;

        public function MapResource(_arg1:String){
            var _local5:int;
            var _local6:int;
            this.m_dirtyRect = new Rectangle();
            this.m_scratchBufferRect = new Rectangle();
            this.m_scratchBufferRenderContext = new RenderContext();
            this.m_worldRect = new Rectangle();
            this.m_arrowRect = new Rectangle();
            this.m_objMat = new Matrix();
            this.sideDirectionMap = new Dictionary();
            this.m_animatedEffects = [];
            this.m_toolTipComponents = new Object();
            super(_arg1);
            m_objectType = Constants.WORLDOBJECT_ITEM;
            m_typeName = "item";
            m_collisionFlags = Constants.COLLISION_ALL;
            if (m_item){
                this.m_ownable = m_item.ownable;
                this.m_storable = m_item.storable;
                setShowHighlight(!(m_item.useTileHighlight));
            } else {
                throw (new Error((("Item " + _arg1) + " does not exist.")));
            };
            this.m_secureRands = new Array();
            this.m_active = false;
            Global.world.citySim.poiManager.addPOI(this);
            this.m_npcNames = Global.world.citySim.npcManager.getAllNpcNames();
            this.m_actionQueue = new NPCActionQueue();
            this.sideDirectionMap[this.LEFT_SIDE] = Constants.DIRECTION_SW;
            this.sideDirectionMap[this.RIGHT_SIDE] = Constants.DIRECTION_NE;
            this.sideDirectionMap[this.TOP_SIDE] = Constants.DIRECTION_NW;
            this.sideDirectionMap[this.BOTTOM_SIDE] = Constants.DIRECTION_SE;
            this.m_statsActionNames = new Dictionary();
            this.statsInit();
            if ((this is NPC)){
                this.m_roundRobbinAnim = false;
            };
            var _local2:String = m_item.xml.animRoundRobbinOpt;
            var _local3:String = m_item.xml.animFramerateOpt;
            if (_local2 != ""){
                _local5 = int(_local2);
                this.m_roundRobbinAnim = !((_local5 == 0));
            };
            if (_local3 != ""){
                _local6 = int(_local3);
                this.m_optFramerate = !((_local6 == 0));
            };
            var _local4 = 1;
            if (m_item.xml.npcPopularity.length() != 0){
                _local4 = int(m_item.xml.npcPopularity);
            };
            this.m_npcPopularity = _local4;
            this.m_supplyStorage = null;
            this.m_upgradeActions = new UpgradeActions(this);
        }
        public function get itemOwner():String{
            return ((this.m_itemOwner) ? this.m_itemOwner : Global.world.ownerId);
        }
        public function set itemOwner(_arg1:String):void{
            this.m_itemOwner = _arg1;
        }
        public function get isPendingOrder():Boolean{
            return (this.m_isPendingOrder);
        }
        public function set isPendingOrder(_arg1:Boolean):void{
            this.m_isPendingOrder = _arg1;
            if (this.m_isPendingOrder){
                lock();
            };
        }
        public function get autoRotate():Boolean{
            var _local1 = !(m_item.noAutoRotate);
            if (m_size.x != m_size.y){
                _local1 = false;
            };
            return (_local1);
        }
        protected function statsInit():void{
            this.m_statsName = m_item.type;
            this.m_statsItemName = m_item.name;
        }
        protected function registerStatsActionName(_arg1:String, _arg2:String):void{
            this.m_statsActionNames[_arg1] = _arg2;
        }
        protected function getStatsActionName(_arg1:String):String{
            return (((this.m_statsActionNames[_arg1]) || (_arg1)));
        }
        public function isRedrawLocked():Boolean{
            return (this.m_lockRedraw);
        }
        public function lockRedraw():void{
            this.m_lockRedraw = true;
        }
        public function unlockRedraw():void{
            this.m_lockRedraw = false;
        }
        public function trackAction(_arg1:String, _arg2:int=1):void{
            this.trackDetailedAction(_arg1, "", "", _arg2);
        }
        public function get harvestingDefinition():Item{
            return (m_item);
        }
        public function trackDetailedAction(_arg1:String, _arg2:String, _arg3:String, _arg4:int=1):void{
            StatsManager.sample(100, StatsKingdomType.GAME_ACTIONS, this.m_statsName, this.getStatsActionName(_arg1), this.m_statsItemName, _arg2, _arg3, _arg4);
        }
        public function trackVisitAction(_arg1:String, _arg2:int=1, _arg3:String=""):void{
            if (Global.world.ownerId != "-1"){
                StatsManager.social(StatsCounterType.SOCIAL_INTERACTIONS, Global.world.ownerId, StatsKingdomType.NEIGHBOR_VISIT, _arg1, _arg3, "", _arg2);
            };
        }
        public function get npcPopularity():int{
            return (this.m_npcPopularity);
        }
        public function set npcPopularity(_arg1:int):void{
            this.m_npcPopularity = _arg1;
        }
        public function get doRoundRobbinAnimOpt():Boolean{
            return (this.m_roundRobbinAnim);
        }
        public function get doFramerateAnimOpt():Boolean{
            return (this.m_optFramerate);
        }
        public function set startTime(_arg1:Number):void{
            this.m_startTime = _arg1;
        }
        public function get content():DisplayObject{
            return (this.m_content);
        }
        public function get displayObject():DisplayObject{
            return (m_displayObject);
        }
        public function get tileScreenPosition():Point{
            var _local1:Vector3 = getReference().getPosition();
            return (IsoMath.tilePosToPixelPos(_local1.x, _local1.y, 0, true));
        }
        public function get currentDepthIndex():Number{
            return (depthIndex);
        }
        public function get displayObjectOffsetX():Number{
            var _local1:Number = (m_displayObject.x - this.tileScreenPosition.x);
            return (_local1);
        }
        public function get displayObjectOffsetY():Number{
            var _local1:Number = (m_displayObject.y - this.tileScreenPosition.y);
            return (_local1);
        }
        public function get npcNames():Array{
            return (this.m_npcNames);
        }
        public function setActive(_arg1:Boolean):void{
            this.m_active = _arg1;
            Global.world.citySim.poiManager.updatePOI(this);
        }
        public function get isActive():Boolean{
            return (this.m_active);
        }
        public function isOwnable():Boolean{
            return (this.m_ownable);
        }
        public function isStorable():Boolean{
            return (this.m_storable);
        }
        public function isUsingPerPixelPick():Boolean{
            return (true);
        }
        public function usingTileHighlight():Boolean{
            return (m_item.useTileHighlight);
        }
        public function usingTilePicking():Boolean{
            return (m_item.useTilePicking);
        }
        public function isSelected():Boolean{
            return (this.m_isSelected);
        }
        public function clearRoadSideFlags():void{
            this.m_adjRoadFlags = 0;
            this.m_connectsToRoad = false;
        }
        public function setRoadSideFlag(_arg1:uint):void{
            this.m_adjRoadFlags = (this.m_adjRoadFlags | _arg1);
        }
        public function setConnectsRoadFlag(_arg1:Boolean):void{
            this.m_connectsToRoad = _arg1;
        }
        public function isRoadAdjacent(_arg1:uint):Boolean{
            return (!(((this.m_adjRoadFlags & _arg1) == 0)));
        }
        public function get isAdjacentToAnyRoad():Boolean{
            return (this.m_connectsToRoad);
        }
        public function getRoadSidePosition(_arg1:uint):Vector3{
            var _local2:Vector3 = getPosition();
            var _local3:Number = (m_size.x * 0.5);
            var _local4:Number = (m_size.y * 0.5);
            _local2.x = (_local2.x + _local3);
            _local2.y = (_local2.y + _local4);
            if (_arg1 == this.LEFT_SIDE){
                _local2.x = (_local2.x - _local3);
            } else {
                if (_arg1 == this.RIGHT_SIDE){
                    _local2.x = (_local2.x + _local3);
                } else {
                    if (_arg1 == this.BOTTOM_SIDE){
                        _local2.y = (_local2.y - _local4);
                    } else {
                        if (_arg1 == this.TOP_SIDE){
                            _local2.y = (_local2.y + _local4);
                        };
                    };
                };
            };
            return (_local2);
        }
        public function get isMoveLocked():Boolean{
            return (this.m_isMoveLocked);
        }
        public function set isMoveLocked(_arg1:Boolean):void{
            this.m_isMoveLocked = _arg1;
        }
        public function unlockMovement():void{
            var mousePos:* = null;
            var tilePos:* = null;
            var currentPos:* = null;
            var offsetPos:* = null;
            var mapResource:* = null;
            if (((((this.m_isMoveLocked) && (Global.player.checkEnergy(-(m_item.unlockMovementEnergyCost))))) && (!(Global.world.isUnlockingMove)))){
                Global.world.isUnlockingMove = true;
                mousePos = new Point(Global.stage.mouseX, Global.stage.mouseY);
                tilePos = IsoMath.screenPosToTilePos(mousePos.x, mousePos.y);
                currentPos = getPosition();
                offsetPos = new Point((tilePos.x - currentPos.x), (tilePos.y - currentPos.y));
                mapResource = this;
                this.m_actionQueue.removeAllStates();
                this.m_actionQueue.addActions(new ActionProgressBar(null, this, ZLoc.t("Main", "Uprooting"), Global.gameSettings.getNumber("actionBarUproot")), new ActionFn(this, function ():void{
                    var _local1:* = new Point(Global.stage.mouseX, Global.stage.mouseY);
                    var _local2:* = IsoMath.screenPosToTilePos(_local1.x, _local1.y);
                    _local2.x = (_local2.x - offsetPos.x);
                    _local2.y = (_local2.y - offsetPos.y);
                    mapResource.setPosition(_local2.x, _local2.y);
                    Sounds.play("click5");
                    Global.world.addGameMode(new GMEditMove());
                    Global.world.addGameMode(new GMObjectMove(mapResource, null, null, Constants.INDEX_NONE, false, currentPos), false);
                    Global.world.isUnlockingMove = false;
                }), new ActionAddEffect(this, EffectType.SIMPLE_BOUNCE));
                this.isMoveLocked = false;
                GameTransactionManager.addTransaction(new TUnlockMovement(this));
            };
        }
        public function get actionQueue():NPCActionQueue{
            return (this.m_actionQueue);
        }
        public function getCoinYield():int{
            return (Math.floor(m_item.coinYield));
        }
        public function getXpYield():int{
            return (Math.floor(m_item.xpYield));
        }
        override public function getSaveObject():Object{
            var _local1:Object = super.getSaveObject();
            _local1.state = this.m_state;
            return (_local1);
        }
        public function get upgradeActions():UpgradeActions{
            return (this.m_upgradeActions);
        }
        public function get upgradeActionCount():int{
            return (this.m_upgradeActionCount);
        }
        public function resetUpgradeActionCount():void{
            this.m_upgradeActionCount = 0;
        }
        public function incrementUpgradeActionCount(_arg1:Boolean=true):void{
            this.m_upgradeActionCount++;
        }
        public function decrementUpgradeActionCount():void{
            this.m_upgradeActionCount = Math.max((this.m_upgradeActionCount - 1), 0);
        }
        override public function loadObject(_arg1:Object):void{
            super.loadObject(_arg1);
            this.m_startTime = _arg1.startTime;
            this.m_itemOwner = ((_arg1.itemOwner) || (""));
            this.m_state = _arg1.state;
            m_direction = _arg1.direction;
            this.m_color = _arg1.color;
            this.m_active = true;
            this.m_currentPopulation = _arg1.currentPopulation;
            this.isMoveLocked = _arg1.isMoveLocked;
            this.m_upgradeActionCount = ((_arg1.upgradeActionCount) || (0));
            updateSize();
            this.updateArrow();
            this.m_supplyStorage = new SupplyStorage(_arg1.supplyStorage);
        }
        override public function getCursor():Class{
            if (Global.world.isEditMode){
                return (super.getCursor());
            };
            return (super.getCursor());
        }
        override public function getMenuPosition(_arg1:Array):Point{
            if (m_displayObject == null){
                return (null);
            };
            var _local2:Number = (((m_displayObject.width / m_displayObject.scaleX) - ContextMenu.ITEM_WIDTH) / 2);
            var _local3:Number = (-(ContextMenu.ITEM_HEIGHT) * _arg1.length);
            return (m_displayObject.localToGlobal(new Point(_local2, _local3)));
        }
        protected function getCurrentImage():ItemImageInstance{
            if (m_item == null){
                return (null);
            };
            var _local1:ItemImageInstance = m_item.getCachedImage(this.m_state, this, m_direction, this.m_statePhase);
            return (_local1);
        }
        public function isCurrentImageLoading():Boolean{
            if (m_item == null){
                return (false);
            };
            return (m_item.isCachedImageLoading(this.m_state, m_direction, this.m_statePhase));
        }
        public function reloadImage():void{
            this.m_itemImage = null;
            this.m_maskBitmap = null;
            setDisplayObjectDirty(true);
            conditionallyRedraw();
        }
        public function loadCurrentImage():void{
            this.getCurrentImage();
        }
        override protected function onItemImageLoaded(_arg1:Event):void{
            this.m_itemImage = null;
            super.onItemImageLoaded(_arg1);
        }
        override public function createDisplayObject():DisplayObject{
            var _local1:DisplayObject = new Sprite();
            m_displayObject = _local1;
            conditionallyRedraw(true);
            return (m_displayObject);
        }
        public function isDrawImageLoading():Boolean{
            if (m_item == null){
                return (false);
            };
            return (m_item.isCachedImageLoading(this.m_state, m_direction, this.m_statePhase));
        }
        public function widthOverride():Number{
            return (-1);
        }
        public function heightOverride():Number{
            return (-1);
        }
        public function colorOverride():Boolean{
            return (false);
        }
        public function colorOverrideHue():uint{
            return (0);
        }
        public function colorOverrideAlpha():Number{
            return (0);
        }
        override public function drawDisplayObject():void{
            var _local2:MovieClip;
            var _local3:Loader;
            var _local4:ColorMaskedBitmap;
            var _local5:Object;
            var _local6:ColorTransform;
            var _local1:Sprite = (m_displayObject as Sprite);
            if (_local1 == null){
                this.createDisplayObject();
            };
            if (_local1 != null){
                _local2 = null;
                _local3 = null;
                if (this.m_itemImage == null){
                    this.m_imageClass = this.getCurrentImage();
                    if (this.m_itemImage != null){
                        return;
                    };
                    if (this.m_imageClass){
                        if ((this.m_imageClass.image is Class)){
                            this.m_itemImage = new this.m_imageClass.image();
                            if ((this.m_itemImage is MovieClip)){
                                _local2 = (this.m_itemImage as MovieClip);
                                _local3 = (_local2.getChildAt(0) as Loader);
                                _local3.contentLoaderInfo.addEventListener(Event.COMPLETE, this.onImageLoaded);
                            } else {
                                this.replaceContent(this.m_itemImage);
                            };
                        } else {
                            if ((((this.m_imageClass.image is String)) && (!((this.m_imageClass.image == null))))){
                                this.m_itemImage = LoadingManager.load((this.m_imageClass.image as String), this.onImageLoaded);
                            } else {
                                if ((this.m_imageClass.image is ColorMaskedBitmap)){
                                    _local4 = (this.m_imageClass.image as ColorMaskedBitmap);
                                    _local4.color = this.m_color;
                                    this.m_itemImage = (this.m_imageClass.image as ColorMaskedBitmap);
                                    this.replaceContent(this.m_itemImage);
                                } else {
                                    if ((this.m_imageClass.image is Bitmap)){
                                        this.m_itemImage = (this.m_imageClass.image as Bitmap);
                                        this.replaceContent(this.m_itemImage);
                                    } else {
                                        if ((this.m_imageClass.image is Loader)){
                                            _local3 = (this.m_imageClass.image as Loader);
                                            this.m_itemImage = _local3;
                                            if (((!(Global.playAnimations)) && ((this.m_imageClass.lowResImage is Bitmap)))){
                                                this.replaceContent((this.m_imageClass.lowResImage as Bitmap));
                                            } else {
                                                _local3.contentLoaderInfo.addEventListener(Event.COMPLETE, this.onImageLoaded);
                                            };
                                        } else {
                                            if ((this.m_imageClass.image is MovieClip)){
                                                this.m_itemImage = (this.m_imageClass.image as MovieClip);
                                                this.replaceContent(this.m_itemImage);
                                            };
                                        };
                                    };
                                };
                            };
                        };
                    };
                } else {
                    if (((((!(Global.playAnimations)) && (this.m_imageClass))) && ((this.m_imageClass.lowResImage is Bitmap)))){
                        this.replaceContent((this.m_imageClass.lowResImage as Bitmap));
                    } else {
                        _local2 = (this.m_itemImage as MovieClip);
                        if (_local2){
                            _local3 = (_local2.getChildAt(0) as Loader);
                            if (((!((_local3 == null))) && (!((_local3.content == null))))){
                                this.replaceContent(_local3.content);
                            } else {
                                if (((this.m_imageClass) && ((this.m_imageClass.image is MovieClip)))){
                                    this.replaceContent((this.m_imageClass.image as MovieClip));
                                };
                            };
                        } else {
                            if ((this.m_itemImage is Loader)){
                                _local3 = (this.m_itemImage as Loader);
                                if (((_local3) && (_local3.content))){
                                    this.replaceContent(_local3.content);
                                };
                            };
                        };
                    };
                };
                if (this.m_maskBitmap == null){
                    _local5 = this.getMaskBitmap();
                    if ((((_local5 is String)) && ((this.m_maskBitmapLoader == null)))){
                        this.m_maskBitmapLoader = LoadingManager.load(Global.getAssetURL((_local5 as String)), this.onImageMaskLoaded);
                    } else {
                        if ((_local5 is Loader)){
                            this.m_maskBitmapLoader = (_local5 as Loader);
                            this.m_maskBitmapLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, this.onImageMaskLoaded);
                        } else {
                            if ((_local5 is Bitmap)){
                                this.m_maskBitmap = (_local5 as Bitmap);
                            } else {
                                if ((_local5 is DisplayObject)){
                                    this.generateImageMask((_local5 as DisplayObject));
                                };
                            };
                        };
                    };
                };
                if (((((this.m_imageClass) && ((this.m_imageClass.forcedWidth <= 0)))) && (this.m_content))){
                    this.m_imageClass.forcedWidth = this.m_content.width;
                };
                if (this.m_itemImage){
                    if (this.widthOverride() > 0){
                        this.m_itemImage.width = this.widthOverride();
                    };
                    if (this.heightOverride() > 0){
                        this.m_itemImage.height = this.heightOverride();
                    };
                    if (this.colorOverride()){
                        _local6 = new ColorTransform();
                        _local6.color = this.colorOverrideHue();
                        _local6.alphaMultiplier = this.colorOverrideAlpha();
                        this.m_itemImage.transform.colorTransform = _local6;
                    };
                    this.updateDisabled();
                };
            };
        }
        public function replaceContent(_arg1:DisplayObject):void{
            var _local3:MapResourceEffect;
            var _local4:SoundTransform;
            var _local2:Sprite = (m_displayObject as Sprite);
            _local2.mouseEnabled = (_local2.mouseChildren = false);
            this.m_content = _arg1;
            this.setHighlighted(m_highlighted);
            while (_local2.numChildren > 0) {
                _local2.removeChildAt(0);
            };
            _local2.addChild(this.m_content);
            for each (_local3 in this.m_animatedEffects) {
                if ((_local3 is AnimationEffect)){
                    (_local3 as AnimationEffect).reattach();
                };
            };
            dispatchEvent(new Event(REPLACE_CONTENT));
            this.updateRoadState();
            if ((this.m_content is MovieClip)){
                _local4 = new SoundTransform();
                if (Global.player.options.sfxDisabled){
                    _local4.volume = 0;
                } else {
                    _local4.volume = 1;
                };
                MovieClip(this.m_content).soundTransform = _local4;
            };
            this.updateDisplayObjectTransform();
            if (m_arrow){
                _local2.addChild(m_arrow);
                setArrowPosition();
            };
            if (((Game.m_blitting) && ((this.m_scratchBuffer1 == null)))){
                this.m_scratchBuffer1 = new BitmapData(0x0100, 0x0100, true, 0);
            };
            if (((Game.m_blitting) && ((this.m_scratchBuffer2 == null)))){
                this.m_scratchBuffer2 = new BitmapData(0x0100, 0x0100, true, 0);
            };
        }
        protected function getImageScaleFactor():Number{
            var _local1:Number = 1;
            if (((m_item) && (m_item.imageScale))){
                _local1 = m_item.imageScale;
            };
            return (_local1);
        }
        public function getColorTransform():Number{
            return (this.m_colorTransform);
        }
        public function setColorTransform(_arg1:Number):void{
            this.m_colorTransform = _arg1;
        }
        public function getHotspots(_arg1:String=""):Vector.<Vector3>{
            var _local2:Vector.<Vector3> = new Vector.<Vector3>();
            if (((!(m_item)) || (!(this.getItemImageHotspots(m_item, this.m_state, m_direction, _arg1))))){
                _local2[0] = new Vector3(m_position.x, m_position.y);
                return (_local2);
            };
            _local2 = this.getItemImageHotspots(m_item, this.m_state, m_direction, _arg1);
            var _local3:Vector.<Vector3> = new Vector.<Vector3>(_local2.length);
            var _local4:int;
            while (_local4 < _local2.length) {
                _local3[_local4] = this.convertHotspotToAbsolute(_local2[_local4]);
                _local4++;
            };
            return (_local3);
        }
        protected function getItemImageHotspots(_arg1:Item, _arg2:String, _arg3:int, _arg4:String=""):Vector.<Vector3>{
            return (_arg1.getCachedImageHotspots(_arg2, _arg3, _arg4));
        }
        public function getHotspot():Vector3{
            return (this.getHotspots()[0]);
        }
        protected function computeDefaultHotspots():Vector.<Vector3>{
            return (Vector.<Vector3>([new Vector3(0.5, 0.5)]));
        }
        protected function convertHotspotToAbsolute(_arg1:Vector3, ... _args):Vector3{
            return (new Vector3((m_position.x + (_arg1.x * m_item.sizeX)), (m_position.y + (_arg1.y * m_item.sizeY))));
        }
        protected function getDisplayXOffset():Number{
            return (0);
        }
        public function calcDirtyRectMapResource(_arg1:RenderContext):Rectangle{
            var _local3:CompositeItemImage;
            var _local2:Point = new Point();
            if (this.m_lastScreenPosition){
                _local2 = _arg1.transformMatrix.transformPoint(this.m_lastScreenPosition);
                if (this.m_content){
                    _local3 = (this.m_content as CompositeItemImage);
                    if (_local3){
                        this.m_dirtyRect = _local3.getDirtyRect();
                        this.m_dirtyRect.x = (this.m_dirtyRect.x + _local2.x);
                        this.m_dirtyRect.y = (this.m_dirtyRect.y + _local2.y);
                    } else {
                        if ((this.m_content is Bitmap)){
                            this.m_dirtyRect.x = _local2.x;
                            this.m_dirtyRect.y = _local2.y;
                            this.m_dirtyRect.width = this.m_content.width;
                            this.m_dirtyRect.height = this.m_content.height;
                        };
                    };
                };
            };
            return (this.m_dirtyRect.clone());
        }
        override public function render(_arg1:RenderContext):void{
            var _local2:Number;
            var _local3:Number;
            var _local4:Bitmap;
            var _local5:CompositeItemImage;
            var _local6:Point;
            if (((isWithinViewport()) && (this.m_content))){
                if (((((renderBufferDirty) && (this.m_scratchBuffer1))) && (this.m_scratchBuffer2))){
                    _local2 = (m_displayObject.scaleX * _arg1.transformMatrix.a);
                    _local3 = (m_displayObject.scaleY * _arg1.transformMatrix.d);
                    if (m_arrow){
                        this.m_arrowRect.x = (_local2 * m_arrow.x);
                        this.m_arrowRect.y = (_local3 * m_arrow.y);
                        this.m_arrowRect.width = (_local2 * m_arrow.width);
                        this.m_arrowRect.height = (_local3 * m_arrow.height);
                    } else {
                        this.m_arrowRect.x = 0;
                        this.m_arrowRect.y = 0;
                        this.m_arrowRect.width = (_local2 * this.m_content.width);
                        this.m_arrowRect.height = (_local3 * this.m_content.height);
                    };
                    this.m_worldRect.x = 0;
                    this.m_worldRect.y = 0;
                    this.m_worldRect.width = (_local2 * this.m_content.width);
                    this.m_worldRect.height = (_local3 * this.m_content.height);
                    this.m_worldRect = this.m_worldRect.union(this.m_arrowRect);
                    _local4 = (this.m_content as Bitmap);
                    if (_local4){
                        this.renderBitmapToScratchBuffer(_local4, (m_arrow as Bitmap), _local2, _local3, this.m_worldRect, this.m_arrowRect);
                    };
                    renderBufferDirty = false;
                };
                if (!renderBufferDirty){
                    if ((this.m_content is Bitmap)){
                        _local6 = _arg1.transformMatrix.transformPoint(m_screenPosition);
                        _arg1.transformMatrix.transformPoint(m_screenPosition).x = (_local6.x + this.m_worldRect.x);
                        _local6.y = (_local6.y + this.m_worldRect.y);
                        _local6.x = (_local6.x - m_pixelOffset);
                        _local6.y = (_local6.y - m_pixelOffset);
                        _arg1.targetBuffer.copyPixels(this.m_scratchBuffer2, this.m_scratchBufferRect, _local6, null, null, true);
                    };
                    _local5 = (this.m_content as CompositeItemImage);
                    if (_local5){
                        _local6 = _arg1.transformMatrix.transformPoint(m_screenPosition);
                        this.m_objMat.a = (m_displayObject.scaleX * _arg1.transformMatrix.a);
                        this.m_objMat.d = (m_displayObject.scaleY * _arg1.transformMatrix.d);
                        this.m_objMat.tx = _local6.x;
                        this.m_objMat.ty = _local6.y;
                        _local5.renderCiToBufferOld(_arg1.targetBuffer, _arg1.alphaBuffer, this.m_objMat, this.alpha);
                    };
                };
                if (!this.m_lastScreenPosition){
                    this.m_lastScreenPosition = new Point();
                };
                this.m_lastScreenPosition.x = m_screenPosition.x;
                this.m_lastScreenPosition.y = m_screenPosition.y;
            };
        }
        protected function renderBitmapToScratchBuffer(_arg1:Bitmap, _arg2:Bitmap, _arg3:Number, _arg4:Number, _arg5:Rectangle, _arg6:Rectangle):void{
            var _local9:ColorTransform;
            var _local10:ColorTransform;
            var _local7:Point = new Point(-(_arg5.x), -(_arg5.y));
            this.m_scratchBuffer1.fillRect(this.m_scratchBuffer1.rect, 0);
            this.m_scratchBuffer2.fillRect(this.m_scratchBuffer2.rect, 0);
            var _local8:Matrix = new Matrix();
            _local8.tx = _local7.x;
            _local8.ty = _local7.y;
            _local8.a = _arg3;
            _local8.d = _arg4;
            _local8.tx = (_local8.tx + m_pixelOffset);
            _local8.ty = (_local8.ty + m_pixelOffset);
            if (this.alpha < 1){
                _local9 = new ColorTransform();
                _local9.alphaMultiplier = this.alpha;
                this.m_scratchBuffer1.draw(_arg1, _local8, _local9);
            } else {
                this.m_scratchBuffer1.draw(_arg1, _local8);
            };
            if (_arg2){
                _local8.tx = (_local7.x + (_arg3 * _arg6.x));
                _local8.ty = (_local7.y + (_arg4 * _arg6.y));
                _local8.a = _arg3;
                _local8.d = _arg4;
                _local8.tx = (_local8.tx + m_pixelOffset);
                _local8.ty = (_local8.ty + m_pixelOffset);
                if (this.alpha < 1){
                    _local10 = new ColorTransform();
                    _local10.alphaMultiplier = this.alpha;
                    this.m_scratchBuffer1.draw(_arg2, _local8, _local10);
                };
                this.m_scratchBuffer1.draw(_arg2, _local8);
            };
            this.m_scratchBufferRect.width = (_arg5.width + (2 * m_pixelOffset));
            this.m_scratchBufferRect.height = (_arg5.height + (2 * m_pixelOffset));
            this.m_scratchBufferRect.x = 0;
            this.m_scratchBufferRect.y = 0;
            if ((((m_displayObject.filters.length > 0)) && (m_highlighted))){
                this.m_scratchBuffer2.applyFilter(this.m_scratchBuffer1, this.m_scratchBufferRect, new Point(), m_displayObject.filters[0]);
            } else {
                this.m_scratchBuffer2.copyPixels(this.m_scratchBuffer1, this.m_scratchBufferRect, new Point(), null, null, true);
            };
        }
        protected function renderCompositeItemImageToScratchBuffer(_arg1:CompositeItemImage, _arg2:Bitmap, _arg3:Number, _arg4:Number, _arg5:Rectangle, _arg6:Rectangle):void{
            var _local9:ColorTransform;
            var _local7:Point = new Point(-(_arg5.x), -(_arg5.y));
            this.m_scratchBuffer1.fillRect(this.m_scratchBuffer1.rect, 0);
            this.m_scratchBuffer2.fillRect(this.m_scratchBuffer2.rect, 0);
            var _local8:Matrix = new Matrix();
            _local8.tx = _local7.x;
            _local8.ty = _local7.y;
            _local8.a = _arg3;
            _local8.d = _arg4;
            _local8.tx = (_local8.tx + m_pixelOffset);
            _local8.ty = (_local8.ty + m_pixelOffset);
            _arg1.renderCiToBufferOld(this.m_scratchBuffer1, null, _local8, this.alpha);
            if (_arg2){
                _local8.tx = (_local7.x + (_arg3 * _arg6.x));
                _local8.ty = (_local7.y + (_arg4 * _arg6.y));
                _local8.a = _arg3;
                _local8.d = _arg4;
                _local8.tx = (_local8.tx + m_pixelOffset);
                _local8.ty = (_local8.ty + m_pixelOffset);
                if (this.alpha < 1){
                    _local9 = new ColorTransform();
                    _local9.alphaMultiplier = this.alpha;
                    this.m_scratchBuffer1.draw(_arg2, _local8, _local9);
                } else {
                    this.m_scratchBuffer1.draw(_arg2, _local8);
                };
            };
            this.m_scratchBufferRect.width = (_arg5.width + (2 * m_pixelOffset));
            this.m_scratchBufferRect.height = (_arg5.height + (2 * m_pixelOffset));
            this.m_scratchBufferRect.x = 0;
            this.m_scratchBufferRect.y = 0;
            if ((((m_displayObject.filters.length > 0)) && (m_highlighted))){
                this.m_scratchBuffer2.applyFilter(this.m_scratchBuffer1, this.m_scratchBufferRect, new Point(), m_displayObject.filters[0]);
            } else {
                this.m_scratchBuffer2.copyPixels(this.m_scratchBuffer1, this.m_scratchBufferRect, new Point(), null, null, true);
            };
        }
        protected function adjustSize(_arg1:Vector3):void{
        }
        override public function updateDisplayObjectTransform():void{
            var _local10:Number;
            var _local11:Number;
            super.updateDisplayObjectTransform();
            var _local1:Vector3 = getReference().getPosition();
            var _local2:Vector3 = getReference().getSize();
            this.adjustSize(_local2);
            m_screenPosition = IsoMath.tilePosToPixelPos(_local1.x, _local1.y, 0, true);
            var _local3:Vector2 = IsoMath.getPixelDeltaFromTileDelta(_local2.x, 0);
            var _local4:Vector2 = IsoMath.getPixelDeltaFromTileDelta(0, _local2.y);
            var _local5:Number = Math.abs((_local3.x - _local4.x));
            var _local6:Number = -1;
            var _local7:Number = 0;
            if (this.m_content){
                _local10 = 0;
                if (((this.m_imageClass) && ((this.m_imageClass.forcedWidth > 0)))){
                    _local10 = this.m_imageClass.forcedWidth;
                } else {
                    _local10 = this.m_content.width;
                };
                if (((this.m_imageClass) && ((this.m_imageClass.forcedHeight > 0)))){
                    _local6 = this.m_imageClass.forcedHeight;
                };
                if (m_item.noAutoScale == false){
                    _local11 = ((_local5 / _local10) * this.getImageScaleFactor());
                    m_displayObject.scaleX = (m_displayObject.scaleY = _local11);
                } else {
                    m_displayObject.scaleX = (m_displayObject.scaleY = (1 / maxZoom));
                };
                _local7 = this.getDisplayXOffset();
            };
            if (_local6 <= 0){
                if (((this.m_imageClass) && (this.m_imageClass.lowResImage))){
                    _local6 = (this.m_imageClass.lowResImage.height * m_displayObject.scaleY);
                } else {
                    _local6 = m_displayObject.height;
                };
            } else {
                _local6 = (_local6 * m_displayObject.scaleY);
            };
            var _local8:Number = 0;
            var _local9:Number = 0;
            if (m_item != null){
                _local8 = m_item.imageOffsetX;
                _local9 = m_item.imageOffsetY;
            };
            this.itemImageOffsetX = 0;
            this.itemImageOffsetY = 0;
            if (((this.m_imageClass) && (this.m_imageClass.offsetX))){
                this.itemImageOffsetX = this.m_imageClass.offsetX;
            };
            if (((this.m_imageClass) && (this.m_imageClass.offsetY))){
                this.itemImageOffsetY = this.m_imageClass.offsetY;
            };
            m_displayObject.x = ((((m_screenPosition.x + (_local4.x * this.getImageScaleFactor())) + _local7) + _local8) + (this.itemImageOffsetX * m_displayObject.scaleX));
            m_displayObject.y = ((((m_screenPosition.y - _local6) + _local9) + (this.itemImageOffsetY * m_displayObject.scaleY)) - (_local1.z * Constants.TILE_WIDTH));
            m_screenPosition.x = m_displayObject.x;
            m_screenPosition.y = m_displayObject.y;
            m_displayObject.visible = true;
        }
        private function onImageLoaded(_arg1:Event):void{
            var _local2:LoaderInfo = (_arg1.target as LoaderInfo);
            _local2.removeEventListener(Event.COMPLETE, this.onImageLoaded);
            conditionallyRedraw(true);
        }
        private function onImageMaskLoaded(_arg1:Event):void{
            var _local2:DisplayObject;
            if (((this.m_maskBitmapLoader) && (this.m_maskBitmapLoader.content))){
                this.m_maskBitmapLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, this.onImageMaskLoaded);
                _local2 = this.m_maskBitmapLoader.content;
                if (((!((_local2.width == 0))) && (!((_local2.height == 0))))){
                    this.generateImageMask(_local2);
                };
            };
        }
        private function generateImageMask(_arg1:DisplayObject):void{
            if (_arg1){
                if (this.m_maskBitmap != null){
                    this.m_maskBitmap.bitmapData.dispose();
                };
            };
        }
        public function setState(_arg1:String):void{
            var _local2:String = this.m_state;
            this.m_state = _arg1;
            this.onStateChanged(_local2, _arg1);
            this.reloadImage();
            if (_arg1 != _local2){
                dispatchEvent(new GameObjectEvent(GameObjectEvent.STATE_CHANGE));
            };
        }
        protected function onStateChanged(_arg1:String, _arg2:String):void{
            this.updateArrow();
        }
        public function onBuildingConstructionCompleted_PreServerUpdate():void{
        }
        public function onBuildingConstructionCompleted_PostServerUpdate():void{
        }
        public function getState():String{
            return (this.m_state);
        }
        protected function updateArrow():void{
        }
        public function refreshArrow():void{
            this.updateArrow();
        }
        protected function updateDisabled():void{
        }
        override public function checkInternalCollision(_arg1:int, _arg2:int, _arg3:int):Boolean{
            return (CollisionMap.compareCollisionFlags(this.getCollisionFlags(_arg1, _arg2), _arg3));
        }
        override public function getCollisionFlags(_arg1:int, _arg2:int):int{
            var _local5:int;
            var _local6:Array;
            var _local3:int;
            _local3 = m_collisionFlags;
            var _local4:Item = getItem();
            if (_local4){
                _local6 = _local4.getCollisionData();
                if (isRotated()){
                    _local5 = ((_arg1 * _local4.sizeX) + _arg2);
                } else {
                    _local5 = ((_arg2 * _local4.sizeX) + _arg1);
                };
                if (_local6.length > _local5){
                    _local3 = _local6[_local5];
                };
            };
            return (_local3);
        }
        private function get alreadyPurchased():Boolean{
            return ((m_id > 0));
        }
        override public function onObjectDrag(_arg1:Vector3):void{
            super.onObjectDrag(_arg1);
            this.m_isDragged = true;
        }
        override public function onObjectDrop(_arg1:Vector3):void{
            super.onObjectDrop(_arg1);
            this.m_isDragged = false;
            this.m_active = true;
            this.calculateDepthIndex();
            this.conditionallyReattach(true);
            Global.world.onResourceChange(this, _arg1, getPosition());
            Global.world.citySim.roadManager.updateRoads(this);
            Global.world.citySim.poiManager.updatePOI(this);
        }
        public function updateRoadState():void{
            var _local1:MapResourceEffect;
            if (!this.m_isRoadVerifiable){
                return;
            };
            if (this.isNeedingRoad){
                if (this.m_roadNotAdjacentEffects){
                    for each (_local1 in this.m_roadNotAdjacentEffects) {
                        _local1.reattach();
                    };
                } else {
                    this.m_roadNotAdjacentEffects = [];
                    this.m_roadNotAdjacentEffects[this.m_roadNotAdjacentEffects.length] = MapResourceEffectFactory.createEffect(this, EffectType.SEPIA);
                    this.m_roadNotAdjacentEffects[this.m_roadNotAdjacentEffects.length] = MapResourceEffectFactory.createEffect(this, EffectType.BAD_SIGN);
                };
            } else {
                if (this.m_roadNotAdjacentEffects){
                    for each (_local1 in this.m_roadNotAdjacentEffects) {
                        _local1.cleanUp();
                    };
                    this.m_roadNotAdjacentEffects = null;
                    this.removeAnimatedEffects();
                };
            };
        }
        public function get isRoadVerifiable():Boolean{
            return (this.m_isRoadVerifiable);
        }
        public function get isNeedingRoad():Boolean{
            var _local1:Boolean;
            if (((this.m_isRoadVerifiable) && (!(Global.world.isOwnerCitySam)))){
                _local1 = !(this.isAdjacentToAnyRoad);
            } else {
                _local1 = false;
            };
            return (_local1);
        }
        public function get svrIsAdjacentToAnyRoad():Boolean{
            return (this.m_dbgServerConnectsToRoad);
        }
        public function isBeingMoved():Boolean{
            return (this.m_isDragged);
        }
        protected function get isUxLockedByQuests():Boolean{
            return (false);
        }
        override public function onSell():void{
            m_sellDialogShowing = false;
            super.onSell();
            Global.world.onResourceChange(this, this.getPosition(), null);
            Global.world.citySim.roadManager.updateRoads(this);
            Global.world.citySim.poiManager.removePOI(this);
        }
        override protected function sellConfirmationHandler(_arg1:GenericPopupEvent):void{
            var _local3:Boolean;
            m_sellDialogShowing = false;
            var _local2 = (_arg1.button == GenericPopup.YES);
            if (_local2){
                if (this.sellSendsToInventory){
                    this.sendToInventory();
                } else {
                    if (m_item){
                        _local3 = (m_item.className == "LotSite");
                        if (((_local3) && (!((UI.m_catalog == null))))){
                            UI.m_catalog.updateChangedCells();
                        };
                    };
                    super.sellConfirmationHandler(_arg1);
                };
            };
            this.trackDetailedAction(TrackedActionType.SELL, "successful", "");
            this.trackDetailedAction(TrackedActionType.SELL, "age", "", this.getAge());
        }
        override public function isPixelInside(_arg1:Point):Boolean{
            var _local3:BitmapData;
            var _local4:Point;
            var _local2:Boolean = super.isPixelInside(_arg1);
            if (_local2){
                if (this.m_maskBitmap){
                    _local3 = this.m_maskBitmap.bitmapData;
                    _local4 = _arg1.subtract(new Point(m_displayObject.x, m_displayObject.y));
                    _arg1.subtract(new Point(m_displayObject.x, m_displayObject.y)).x = (_local4.x / m_displayObject.scaleX);
                    _local4.y = (_local4.y / m_displayObject.scaleY);
                    _local4.x = (_local4.x - this.m_maskBitmap.x);
                    _local4.y = (_local4.y - this.m_maskBitmap.y);
                    _local2 = _local3.hitTest(new Point(0, 0), this.getItem().isPixelInsideAlphaThresholdOveride, _local4);
                };
            };
            return (_local2);
        }
        protected function getCurrentImageForMask():ItemImageInstance{
            return (this.getCurrentImage());
        }
        protected function getMaskBitmap():Object{
            var _local1:Object;
            var _local2:ItemImageInstance;
            var _local3:DisplayObject;
            var _local4:CompositeItemImage;
            if (this.isUsingPerPixelPick()){
                _local2 = (this.getCurrentImageForMask() as ItemImageInstance);
                if (_local2){
                    _local3 = (_local2.image as DisplayObject);
                    if ((_local3 is CompositeItemImage)){
                        _local4 = (_local3 as CompositeItemImage);
                        _local3 = _local4.getBuildingImageByType(ItemImageInstance.BUILDING_IMAGE);
                    };
                    if ((_local3 is Bitmap)){
                        _local1 = _local3;
                    } else {
                        if ((_local3 is Loader)){
                            _local1 = _local3;
                        } else {
                            if ((_local3 is MovieClip)){
                                _local1 = _local3;
                            };
                        };
                    };
                };
            } else {
                _local1 = null;
            };
            return (_local1);
        }
        override public function sell():void{
            var _local2:Boolean;
            var _local3:String;
            if (m_sellDialogShowing){
                return;
            };
            m_sellDialogShowing = true;
            var _local1:String = (this.sellSendsToInventory) ? "SendToInventorySpecific" : "SellObjectSpecific";
            if (m_item){
                if ((((((getSellPrice() <= 1)) && ((m_item.cash <= 0)))) && (!(this.sellSendsToInventory)))){
                    _local2 = (m_item.className == "LotSite");
                    sellNow();
                    if (((_local2) && (UI.m_catalog))){
                        UI.m_catalog.updateChangedCells();
                    };
                    m_sellDialogShowing = false;
                } else {
                    _local3 = ZLoc.t("Main", _local1, {
                        item:getItemFriendlyName(),
                        coins:getSellPrice()
                    });
                    if (((!((Global.crews.getCrewByObject(this) == null))) && ((Global.crews.getCrewByObject(this).count > 0)))){
                        _local3 = (_local3 + (" " + ZLoc.t("Main", "SendToInventoryCrewWarning")));
                    };
                    UI.displayMessage(_local3, GenericPopup.TYPE_YESNO, this.sellConfirmationHandler, "sellDialog", true);
                };
            } else {
                super.sell();
            };
        }
        public function get sellSendsToInventory():Boolean{
            return (m_item.sellSendsToInventory);
        }
        public function sendToInventory():void{
            var _local1:Boolean = Global.player.inventory.addItems(m_item.name, 1);
            if (_local1){
                GameTransactionManager.addTransaction(new TSendToInventory(this));
                this.detach();
                cleanup();
                this.onSell();
            };
        }
        public function store():void{
            var _local2:BaseStorageUnit;
            var _local3:Array;
            var _local4:ItemStorage;
            var _local1:Vector.<StorageId> = Global.player.storageComponent.getValidStorageUnits(this);
            if (_local1.length < 1){
            } else {
                if (_local1.length == 1){
                    _local2 = Global.player.storageComponent.getStorageUnit(_local1[0].storageType, _local1[0].key);
                };
            };
            if (_local2){
                if (_local2.size < _local2.capacity){
                    _local2.add(this);
                    GameTransactionManager.addTransaction(new TStoreItem(this));
                    this.detach();
                    this.prepareForStorage();
                    this.onSell();
                    _local3 = Global.world.getObjectsByClass(ItemStorage);
                    for each (_local4 in _local3) {
                        _local4.refreshArrow();
                    };
                    this.trackAction(TrackedActionType.STORE);
                } else {
                    UI.displayMessage(ZLoc.t("Dialogs", "warehouseFull"), GenericPopup.TYPE_OK, null, "storageFullDialog", true);
                    this.trackAction("warehouse_full");
                };
                //unresolved jump
            };
        }
        override public function onUpdate(_arg1:Number):void{
            var _local2:MapResourceEffect;
            var _local3:IDynamicDisplayObject;
            var _local4:AnimationEffect;
            super.onUpdate(_arg1);
            if (this.shouldObjectIndicatorBeUpdated()){
                updateObjectIndicator();
            };
            if (this.isVisible()){
                if ((this.m_content is IDynamicDisplayObject)){
                    _local3 = (this.m_content as IDynamicDisplayObject);
                    _local3.onUpdate(_arg1);
                };
                for each (_local2 in this.m_animatedEffects) {
                    if ((_local2 is AnimationEffect)){
                        _local4 = (_local2 as AnimationEffect);
                        if (!_local4.isAutoUpdating){
                            _local4.updateAnimatedBitmap(_arg1);
                        };
                    };
                };
            } else {
                if ((this is Cloud)){
                    CloudManager.removeCloud(Cloud(this));
                };
            };
            this.m_actionQueue.update(_arg1);
        }
        protected function isWrongPlantContract():Boolean{
            return (true);
        }
        override public function onMouseOver(_arg1:MouseEvent):void{
            if (((!(isLocked())) && (!((Global.world.getTopGameMode() is GMObjectMove))))){
                if ((Global.world.getTopGameMode() is GMPlant)){
                    if (this.isWrongPlantContract()){
                        return;
                    };
                };
                setShowHighlight(!(m_item.useTileHighlight));
                this.setHighlighted(true);
            };
        }
        override public function onMouseOut():void{
            this.setHighlighted(false);
        }
        override public function onSelect():void{
            super.onSelect();
            this.m_isSelected = true;
        }
        override public function onDeselect():void{
            super.onDeselect();
            this.m_isSelected = false;
        }
        override public function setHighlighted(_arg1:Boolean, _arg2:uint=16755200):void{
            var _local3:Boolean = (this.isHighlightable) ? _arg1 : false;
            m_highlighted = _local3;
            if (this.m_content){
                if (((_local3) && (canShowHighlight))){
                    this.m_content.filters = [new GlowFilter(getHighlightColor(), 1, 8, 8, 20)];
                } else {
                    this.m_content.filters = m_filters.concat([]);
                };
                if (this.m_visitorHighlight){
                    this.m_content.filters = this.m_content.filters.concat(new GlowFilter(EmbeddedArt.VISITOR_INTERACTED_HIGHLIGHT_COLOR, 1, 20, 20, 2));
                };
                renderBufferDirty = true;
            };
        }
        public function setHighlightedSpecial(_arg1:Boolean, _arg2:uint, _arg3:int):void{
            if (this.m_content){
                this.m_content.filters = [new GlowFilter(_arg2, 1, _arg3, _arg3, 20)];
                renderBufferDirty = true;
            };
        }
        public function setVisitorInteractedHighlighted(_arg1:Boolean=true):void{
            this.m_visitorHighlight = _arg1;
            this.setHighlighted(m_highlighted);
        }
        public function isPaintable():Boolean{
            var _local1:ColorMaskedBitmap = (this.getItemImage() as ColorMaskedBitmap);
            return (!((_local1 == null)));
        }
        public function onRotateMenuAction(_arg1:MouseEvent):void{
            var _local2:int = m_direction;
            this.rotate();
            Global.world.addGameMode(new GMObjectMove(this, this.m_state, null, _local2), false);
        }
        public function rotate():void{
            m_direction++;
            if (m_direction >= Constants.DIRECTION_MAX){
                m_direction = Constants.DIRECTION_SW;
            };
            updateSize();
            if (!this.m_lockRedraw){
                this.m_itemImage = null;
                this.m_maskBitmap = null;
                setDisplayObjectDirty(true);
                conditionallyRedraw();
            };
        }
        public function rotateToDirection(_arg1:int):void{
            while (_arg1 != m_direction) {
                this.rotate();
            };
        }
        public function onSellMenuAction(_arg1:MouseEvent):void{
            this.sell();
        }
        public function onPaintMenuAction(_arg1:MouseEvent):void{
            var _local2:SWFDialog = new PaintSelector();
            UI.displayPopup(_local2);
        }
        public function setColor(_arg1:uint):void{
            this.m_color = _arg1;
            var _local2:ColorMaskedBitmap = (this.m_itemImage as ColorMaskedBitmap);
            if (_local2){
                _local2.color = _arg1;
            };
        }
        public function getColor():uint{
            return (this.m_color);
        }
        public function getAge():Number{
            return ((this.m_startTime) ? (GlobalEngine.serverTime - this.m_startTime) : 0);
        }
        public function getItemImage():DisplayObject{
            return (this.m_itemImage);
        }
        public function onEditModeSwitch():void{
        }
        override public function onMenuClick(_arg1:MouseEvent):void{
            var _local2:ContextMenuItem;
            if ((_arg1.target is ContextMenuItem)){
                _local2 = (_arg1.target as ContextMenuItem);
                switch (_local2.action){
                    case MOVE_OBJECT:
                        this.move();
                        break;
                    case SELL_OBJECT:
                        this.sell();
                        break;
                    default:
                        super.onMenuClick(_arg1);
                };
            };
        }
        protected function shouldToolTipBeUpdated():Boolean{
            return (((((isHighlighted()) || (this.isSelected()))) || (this.isBeingMoved())));
        }
        protected function shouldObjectIndicatorBeUpdated():Boolean{
            return (((((isHighlighted()) || (this.isSelected()))) && (!(this.m_isDragged))));
        }
        override public function getToolTipHeader():String{
            var _local1:String;
            if (m_item){
                _local1 = getItemFriendlyName();
            };
            return (_local1);
        }
        override public function getToolTipNotes():String{
            var _local1:String;
            if (this.m_isPendingOrder){
                _local1 = ZLoc.t("Main", "OwnershipPending");
            } else {
                if (((m_item) && (!((m_item.tooltipNotes == ""))))){
                    _local1 = m_item.tooltipNotes;
                };
            };
            return (_local1);
        }
        override public function getToolTipAction():String{
            return (this.getGameModeToolTipAction());
        }
        protected function prepTooltipLabel(_arg1:JLabel):JLabel{
            var _local2:ToolTipSchema = ToolTipSchema.getSchemaForObject(this);
            var _local3:ASFont = new ASFont(_local2.bodyFontName, _local2.bodyFontSize, false, false, false, new ASFontAdvProperties(true, AntiAliasType.ADVANCED, GridFitType.PIXEL));
            _arg1.setForeground(new ASColor(_local2.bodyFontColor));
            _arg1.setFont(_local3);
            _arg1.setTextFilters(_local2.bodyTextFilters);
            return (_arg1);
        }
        protected function buildToolTipComponent(_arg1:String, _arg2:String):Component{
            var _local3:JPanel = this.m_toolTipComponents[(_arg1 + "_container")];
            var _local4:JLabel = this.m_toolTipComponents[(_arg1 + "_label")];
            if (_arg2){
                _local4 = ((_local4) || (this.prepTooltipLabel(new JLabel(""))));
                _local3 = ((_local3) || (ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT)));
                _local3.removeAll();
                _local4.setText(_arg2);
                _local3.appendAll(_local4);
            } else {
                if (_local3){
                    _local3.removeAll();
                };
                _local3 = null;
                _local4 = null;
            };
            this.m_toolTipComponents[(_arg1 + "_container")] = _local3;
            this.m_toolTipComponents[(_arg1 + "_label")] = _local4;
            return (_local3);
        }
        protected function getToolTipTextWidth(_arg1:String):Number{
            var _local2:ToolTipSchema = ToolTipSchema.getSchemaForObject(this);
            if (!this.m_stringWidthTester){
                this.m_stringWidthTester = ASwingHelper.makeTextField("", _local2.bodyFontName, _local2.bodyFontSize, _local2.bodyFontColor);
            };
            this.m_stringWidthTester.setTextFormat(new TextFormat(_local2.bodyFontName, _local2.bodyFontSize, _local2.bodyFontColor));
            this.m_stringWidthTester.setText(_arg1);
            return (this.m_stringWidthTester.getTextField().textWidth);
        }
        override public function getToolTipFloatOffset():int{
            var _local1:int;
            if (this.m_stagePickEffect){
                _local1 = this.m_stagePickEffect.getAnimationHeight();
            };
            return ((super.getToolTipFloatOffset() + _local1));
        }
        public function getToolTipComponentList():Array{
            return ([this.getCustomToolTipAction(), this.getCustomToolTipStatus(), this.getCustomToolTipLevelBar()]);
        }
        public function getCustomToolTipTitle():String{
            return (this.getToolTipHeader());
        }
        public function getCustomToolTipImage():Component{
            return (null);
        }
        public function getCustomToolTipStatus():Component{
            return (this.buildToolTipComponent(ToolTipDialog.STATUS, getToolTipStatus()));
        }
        public function getCustomToolTipAction():Component{
            return (this.buildToolTipComponent(ToolTipDialog.ACTION, (this.getToolTipAction()) ? TextFieldUtil.formatSmallCapsString(this.getToolTipAction()) : null));
        }
        public function getCustomToolTipLevelBar():Component{
            var _local1:Number;
            var _local2:Number;
            if (this.canCountUpgradeActions()){
                _local1 = Number(this.getItem().upgrade.requirements.getRequirementValue(Requirements.REQUIREMENT_UPGRADE_ACTIONS));
                _local2 = Math.min(this.upgradeActions.getTotal(), _local1);
                if (!this.m_levelProgressComponent){
                    this.m_levelProgressComponent = new SimpleProgressBar(EmbeddedArt.darkBlueToolTipColor, EmbeddedArt.UPGRADE_HIGHLIGHT_COLOR, 100, 10, 2, -5);
                };
                this.m_levelProgressComponent.setBgAlpha(1);
                this.m_levelProgressComponent.setBgColor(2450817);
                this.m_levelProgressComponent.setProgressRatio(_local2, _local1);
                this.m_levelProgressComponent.setTitle(ZLoc.t("Main", "LevelProgress"));
            } else {
                if (this.canShowAlternativeUpgradeToolTip()){
                    if (!this.m_alternativeLevelLabel){
                        this.m_alternativeLevelLabel = new JLabel("", null, JLabel.LEFT);
                        this.m_alternativeLevelLabel.setFont(new ASFont(EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 14, false, false, false, new ASFontAdvProperties(true, AntiAliasType.ADVANCED, GridFitType.PIXEL)));
                        this.m_alternativeLevelLabel.setForeground(new ASColor(EmbeddedArt.darkBlueToolTipColor));
                    };
                    this.m_alternativeLevelLabel.setText(ZLoc.t("Dialogs", "level_text", {amount:this.getItem().level}));
                    this.m_levelProgressComponent = null;
                    return (this.m_alternativeLevelLabel);
                };
                this.m_levelProgressComponent = null;
            };
            return (this.m_levelProgressComponent);
        }
        public function getGameModeToolTipAction():String{
            var _local1:String;
            var _local2:GameMode = Global.world.getTopGameMode();
            if ((_local2 is GMEditMove)){
                if (!this.isMoveLocked){
                    _local1 = ZLoc.t("Main", "Move_ToolTip");
                } else {
                    _local1 = this.GetNoMoveMessage();
                };
            } else {
                if ((_local2 is GMEditRotate)){
                    _local1 = ZLoc.t("Main", "Rotate_ToolTip");
                } else {
                    if ((_local2 is GMObjectMove)){
                        _local1 = ZLoc.t("Main", "Place_ToolTip");
                    } else {
                        if ((_local2 is GMEditSell)){
                            _local1 = ZLoc.t("Main", "Remove_ToolTip");
                        };
                    };
                };
            };
            return (_local1);
        }
        protected function onSfxChanged(_arg1:FarmGameWorldEvent):void{
            var _local2:SoundTransform;
            if ((this.m_content is MovieClip)){
                _local2 = new SoundTransform();
                if (Global.player.options.sfxDisabled){
                    _local2.volume = 0;
                } else {
                    _local2.volume = 1;
                };
                MovieClip(this.m_content).soundTransform = _local2;
            };
        }
        override public function attach():void{
            super.attach();
            Global.ui.addEventListener(FarmGameWorldEvent.SFX_CHANGED, this.onSfxChanged);
        }
        override public function detach():void{
            super.detach();
            Global.ui.removeEventListener(FarmGameWorldEvent.SFX_CHANGED, this.onSfxChanged);
        }
        override protected function calculateDepthIndex():void{
            super.calculateDepthIndex();
            if (this.isBeingMoved()){
                m_depthIndex = (m_depthIndex - 10000);
            };
        }
        override public function toggleAnimation():void{
            var _local1:Sprite;
            var _local2:int;
            var _local3:DisplayObject;
            if (((this.m_displayObject) && ((this.m_displayObject is Sprite)))){
                _local1 = (m_displayObject as Sprite);
                _local2 = 0;
                while (_local2 < _local1.numChildren) {
                    _local3 = _local1.getChildAt(_local2);
                    this.toggleDispObjAnimation(_local3);
                    _local2++;
                };
                this.toggleDispObjAnimation(this.m_itemImage);
            };
        }
        override public function getDimensions():Vector3{
            if (this.m_itemImage){
                return (new Vector3(this.m_itemImage.width, this.m_itemImage.height));
            };
            return (null);
        }
        public function getItemImageDimensions():Vector3{
            if (m_item){
                return (m_item.getCachedImageDimensions(this.m_state, m_direction));
            };
            return (null);
        }
        override public function preDisableMove(_arg1:String, _arg2:int):void{
            this.setState(_arg1);
            setDirection(_arg2);
        }
        private function toggleDispObjAnimation(_arg1:DisplayObject):void{
            var _local2:Sprite;
            var _local3:int;
            var _local4:DisplayObject;
            if ((_arg1 is MovieClip)){
                if (Global.playAnimations){
                    (_arg1 as MovieClip).play();
                } else {
                    (_arg1 as MovieClip).stop();
                };
            };
            if ((((_arg1 as Sprite)) && (((_arg1 as Sprite).numChildren > 0)))){
                _local2 = (_arg1 as Sprite);
                _local3 = 0;
                while (_local3 < _local2.numChildren) {
                    _local4 = _local2.getChildAt(_local3);
                    if ((_local4 is MovieClip)){
                        if (Global.playAnimations){
                            (_local4 as MovieClip).play();
                        } else {
                            (_local4 as MovieClip).stop();
                        };
                    };
                    _local3++;
                };
            };
        }
        public function onStorage():void{
        }
        public function addEffect(_arg1:String):void{
            if (m_effectLoader == null){
                m_effectLoader = new ImageLoader(Global.getAssetURL(_arg1));
                m_effectLoader.getContent(this.onEffectLoad);
            };
        }
        public function stopEffect():void{
            if (this.m_effectOverlay != null){
                if ((this.m_displayObject as Sprite).contains(this.m_effectOverlay)){
                    (this.m_displayObject as Sprite).removeChild(this.m_effectOverlay);
                };
                (this.m_effectOverlay as MovieClip).stop();
                this.m_effectOverlay = null;
            };
        }
        public function addAnimatedEffect(_arg1:EffectType):MapResourceEffect{
            var _local2:MapResourceEffect = MapResourceEffectFactory.createEffect(this, _arg1);
            return (this.addAnimatedEffectFromInstance(_local2));
        }
        public function addAnimatedEffectFromInstance(_arg1:MapResourceEffect):MapResourceEffect{
            this.m_animatedEffects[this.m_animatedEffects.length] = _arg1;
            return (_arg1);
        }
        public function removeAnimatedEffects():void{
            var _local1:MapResourceEffect;
            for each (_local1 in this.m_animatedEffects) {
                _local1.cleanUp();
                _local1 = null;
            };
            this.m_animatedEffects = [];
        }
        public function removeAnimatedEffectByClass(_arg1:Class):void{
            var _local3:MapResourceEffect;
            var _local2:int;
            while (_local2 < this.m_animatedEffects.length) {
                _local3 = this.m_animatedEffects[_local2];
                if ((_local3 is _arg1)){
                    _local3.cleanUp();
                    this.m_animatedEffects.splice(_local2, 1);
                };
                _local2++;
            };
        }
        public function getAnimatedEffectByClass(_arg1:Class):MapResourceEffect{
            var _local3:MapResourceEffect;
            var _local2:int;
            while (_local2 < this.m_animatedEffects.length) {
                _local3 = this.m_animatedEffects[_local2];
                if ((_local3 is _arg1)){
                    return (_local3);
                };
                _local2++;
            };
            return (null);
        }
        override public function cleanUp():void{
            var _local1:MapResourceEffect;
            this.removeAnimatedEffects();
            if (this.m_roadNotAdjacentEffects){
                for each (_local1 in this.m_roadNotAdjacentEffects) {
                    _local1.cleanUp();
                };
                this.m_roadNotAdjacentEffects = null;
            };
            Global.world.citySim.poiManager.removePOI(this);
            if (this.m_actionQueue){
                this.m_actionQueue.removeAllStates();
            };
            super.cleanUp();
        }
        private function onEffectLoad(_arg1:DisplayObject):void{
            this.stopEffect();
            if (_arg1 != null){
                this.m_effectOverlay = _arg1;
                (this.m_effectOverlay as MovieClip).play();
                if ((this.m_displayObject as Sprite).numChildren > 0){
                    (this.m_displayObject as Sprite).addChild(this.m_effectOverlay);
                    this.m_effectOverlay.x = 0;
                    this.m_effectOverlay.y = 0;
                    this.m_effectOverlay.scaleX = 1;
                    this.m_effectOverlay.scaleY = 1;
                };
            };
            m_effectLoader = null;
        }
        public function deleteArrow():void{
            m_arrow = null;
            this.reloadImage();
        }
        public function clearFromMap():void{
            if (!Global.isVisiting()){
                this.m_doobersArray = Global.player.processRandomModifiers(m_item, this, false, this.m_secureRands);
                Global.world.dooberManager.createBatchDoobers(this.m_doobersArray, m_item, m_position.x, m_position.y);
            };
            if (((this.m_doobersArray) && (this.m_doobersArray.length))){
                this.m_actionQueue.removeAllStates();
                this.m_actionQueue.addActions(new ActionPause(this, 1), new ActionFn(this, function ():void{
                    Global.hud.conditionallyRefreshHUD();
                    detach();
                    cleanUp();
                }));
            } else {
                Global.hud.conditionallyRefreshHUD();
                this.detach();
                this.cleanUp();
            };
            if (m_actionMode != VISIT_REPLAY_ACTION){
                if (!Global.isVisiting()){
                    GameTransactionManager.addTransaction(new TClearMapResource(this));
                };
            };
        }
        private function stringCompare(_arg1:String, _arg2:String):Number{
            if (_arg1 < _arg2){
                return (-1);
            };
            if (_arg1 > _arg2){
                return (1);
            };
            return (0);
        }
        private function checkDooberResults(_arg1:Object):String{
            var clientDoober:* = null;
            var serverDoober:* = null;
            var amount:* = 0;
            var dooberIndex:* = 0;
            var result:* = _arg1;
            var clientDoobers:* = new Array();
            if (this.m_doobersArray != null){
                for each (clientDoober in this.m_doobersArray) {
                    if (!isNaN(clientDoober[1])){
                        clientDoobers.push(new Array(clientDoober[0], int(Math.ceil(clientDoober[1]))));
                    };
                };
                clientDoobers = clientDoobers.sort(function (_arg1:Array, _arg2:Array):Number{
                    return (stringCompare(_arg1[0], _arg2[0]));
                });
            };
            var serverDoobers:* = new Array();
            if (result.doobers != null){
                for each (serverDoober in result.doobers) {
                    if (!isNaN(serverDoober[1])){
                        amount = Math.ceil(serverDoober[1]);
                        serverDoobers.push(new Array(Global.gameSettings.getDooberFromType(serverDoober[0], amount), amount));
                    };
                };
                serverDoobers = serverDoobers.sort(function (_arg1:Array, _arg2:Array):Number{
                    return (stringCompare(_arg1[0], _arg2[0]));
                });
            };
            var error:* = null;
            if (serverDoobers.length > 0){
                if (clientDoobers.length == serverDoobers.length){
                    dooberIndex = 0;
                    while (dooberIndex < serverDoobers.length) {
                        clientDoober = clientDoobers[dooberIndex];
                        serverDoober = serverDoobers[dooberIndex];
                        if (this.stringCompare(clientDoober[0], serverDoober[0]) !== 0){
                            error = "type_mismatch";
                            break;
                        };
                        if (clientDoober[1] !== serverDoober[1]){
                            error = "value_mismatch";
                            break;
                        };
                        dooberIndex = (dooberIndex + 1);
                    };
                } else {
                    error = "count_mismatch";
                };
            } else {
                if (clientDoobers.length > 0){
                    error = "count_mismatch";
                };
            };
            return (error);
        }
        private function checkRandResults(_arg1:Object):String{
            var _local4:int;
            var _local2:String;
            var _local3:Array = _arg1.secureRands;
            if (((!((_local3 == null))) && ((_local3.length > 0)))){
                if (((!((this.m_secureRands == null))) && ((this.m_secureRands.length >= _local3.length)))){
                    _local4 = 0;
                    while (_local4 < _local3.length) {
                        if (_local3[_local4] != this.m_secureRands[_local4]){
                            _local2 = "Secure Rand didn't match";
                            break;
                        };
                        _local4++;
                    };
                    this.m_secureRands.splice(0, _local3.length);
                } else {
                    this.m_secureRands.splice(0, this.m_secureRands.length);
                    _local2 = "Client has fewer secure rand results than server.";
                };
            } else {
                if (((!((this.m_secureRands == null))) && ((this.m_secureRands.length > 0)))){
                    _local2 = "Server did not return any secure rand values.";
                    this.m_secureRands.splice(0, this.m_secureRands.length);
                };
            };
            return (_local2);
        }
        public function parseAndCheckDooberResults(_arg1:Object):void{
            var _local3:String;
            if (!Global.world.dooberManager.isDoobersEnabled()){
                return;
            };
            var _local2:String = this.checkRandResults(_arg1);
            if (_local2 != null){
                _local2 = (_local2 + (" - " + SecureRand.getAndClearDebugBuffer()));
                StatsManager.count(StatsCounterType.ERRORS, StatsKingdomType.SECURERAND, (Config.DEBUG_MODE) ? StatsPhylumType.DEBUG_ERROR : StatsPhylumType.MISCELLANEOUS, "any", this.getItemName());
                Global.world.dooberManager.autoCollect();
                Global.player.forceServerStats();
            };
            if (RuntimeVariableManager.getBoolean("ENABLE_DOOBER_TRACKING", false)){
                _local3 = this.checkDooberResults(_arg1);
                if (_local3 != null){
                    StatsManager.count(StatsCounterType.ERRORS, StatsKingdomType.DOOBER_MISMATCH, (Config.DEBUG_MODE) ? StatsPhylumType.DEBUG_ERROR : StatsPhylumType.MISCELLANEOUS, "any", this.getItemName(), _local3);
                    Utilities.printr(_arg1.doobers);
                    Utilities.printr(this.m_doobersArray);
                };
            };
        }
        public function canClearFromMap():Boolean{
            if (((this.isOwnable()) || (!(isAttached())))){
                return (false);
            };
            if (!Global.player.checkEnergy(-(m_item.clearEnergyCost))){
                displayStatus(ZLoc.t("Main", "NotEnoughEnergyRed"));
                return (false);
            };
            return (true);
        }
        public function getRoadSidewalkSide():uint{
            var _local1:Vector3 = getPosition();
            var _local2:Vector3 = this.getHotspot().subtract(_local1);
            _local2.x = (_local2.x - (m_size.x * 0.5));
            _local2.y = (_local2.y - (m_size.y * 0.5));
            _local2 = _local2.normalize();
            var _local3:uint = this.BOTTOM_SIDE;
            if (Math.abs(_local2.x) > Math.abs(_local2.y)){
                if (_local2.x < 0){
                    if ((this.m_adjRoadFlags & this.LEFT_SIDE)){
                        _local3 = this.LEFT_SIDE;
                    } else {
                        if ((this.m_adjRoadFlags & this.BOTTOM_SIDE)){
                            _local3 = this.BOTTOM_SIDE;
                        } else {
                            if ((this.m_adjRoadFlags & this.TOP_SIDE)){
                                _local3 = this.TOP_SIDE;
                            } else {
                                if ((this.m_adjRoadFlags & this.RIGHT_SIDE)){
                                    _local3 = this.RIGHT_SIDE;
                                };
                            };
                        };
                    };
                } else {
                    if ((this.m_adjRoadFlags & this.BOTTOM_SIDE)){
                        _local3 = this.BOTTOM_SIDE;
                    } else {
                        if ((this.m_adjRoadFlags & this.LEFT_SIDE)){
                            _local3 = this.LEFT_SIDE;
                        } else {
                            if ((this.m_adjRoadFlags & this.RIGHT_SIDE)){
                                _local3 = this.RIGHT_SIDE;
                            } else {
                                if ((this.m_adjRoadFlags & this.TOP_SIDE)){
                                    _local3 = this.TOP_SIDE;
                                };
                            };
                        };
                    };
                };
            } else {
                if (_local2.y < 0){
                    if ((this.m_adjRoadFlags & this.BOTTOM_SIDE)){
                        _local3 = this.BOTTOM_SIDE;
                    } else {
                        if ((this.m_adjRoadFlags & this.LEFT_SIDE)){
                            _local3 = this.LEFT_SIDE;
                        } else {
                            if ((this.m_adjRoadFlags & this.RIGHT_SIDE)){
                                _local3 = this.RIGHT_SIDE;
                            } else {
                                if ((this.m_adjRoadFlags & this.TOP_SIDE)){
                                    _local3 = this.TOP_SIDE;
                                };
                            };
                        };
                    };
                } else {
                    if ((this.m_adjRoadFlags & this.LEFT_SIDE)){
                        _local3 = this.LEFT_SIDE;
                    } else {
                        if ((this.m_adjRoadFlags & this.BOTTOM_SIDE)){
                            _local3 = this.BOTTOM_SIDE;
                        } else {
                            if ((this.m_adjRoadFlags & this.TOP_SIDE)){
                                _local3 = this.TOP_SIDE;
                            } else {
                                if ((this.m_adjRoadFlags & this.RIGHT_SIDE)){
                                    _local3 = this.RIGHT_SIDE;
                                };
                            };
                        };
                    };
                };
            };
            return (_local3);
        }
        public function getHotspotSidewalkSide():uint{
            var _local1:Vector3 = getPosition();
            var _local2:Vector3 = this.getHotspot().subtract(_local1);
            _local2.x = (_local2.x - (m_size.x * 0.5));
            _local2.y = (_local2.y - (m_size.y * 0.5));
            _local2 = _local2.normalize();
            var _local3:uint = this.BOTTOM_SIDE;
            if (Math.abs(_local2.x) > Math.abs(_local2.y)){
                return (((_local2.x)<0) ? this.LEFT_SIDE : this.RIGHT_SIDE);
            };
            return (((_local2.y)<0) ? this.BOTTOM_SIDE : this.TOP_SIDE);
        }
        public function sidewalkSideToNormalVector(_arg1:int):Vector3{
            switch (_arg1){
                case this.LEFT_SIDE:
                    return (new Vector3(-1, 0));
                case this.RIGHT_SIDE:
                    return (new Vector3(1, 0));
                case this.TOP_SIDE:
                    return (new Vector3(0, 1));
                case this.BOTTOM_SIDE:
                    return (new Vector3(0, -1));
                default:
                    return (null);
            };
        }
        public function getNthSidewalkPosition(_arg1:int, _arg2:int):Vector3{
            var _local3:Vector3 = getPosition();
            var _local4:Number = 0;
            var _local5:Number = (m_size.y / _arg2);
            var _local6:uint = this.getRoadSidewalkSide();
            if ((_local6 & this.LEFT_SIDE)){
            } else {
                if ((_local6 & this.BOTTOM_SIDE)){
                    _local4 = (m_size.x / _arg2);
                    _local5 = 0;
                } else {
                    if ((_local6 & this.TOP_SIDE)){
                        _local3.y = (_local3.y + m_size.y);
                        _local4 = (m_size.x / _arg2);
                        _local5 = 0;
                    } else {
                        if ((_local6 & this.RIGHT_SIDE)){
                            _local3.x = (_local3.x + m_size.x);
                        };
                    };
                };
            };
            _local3.x = (_local3.x + (_local4 * (_arg1 - 0.75)));
            _local3.y = (_local3.y + (_local5 * (_arg1 - 0.75)));
            return (_local3);
        }
        public function findValidCrowdPosition():Vector3{
            var _local1:Vector3 = new Vector3(0, 0, 1);
            var _local2:Number = 1;
            var _local3:Number = 2;
            var _local4:Vector3 = this.getHotspot();
            var _local5:Vector3 = this.sidewalkSideToNormalVector(this.getHotspotSidewalkSide());
            var _local6:Vector3 = _local5.cross(_local1).normalize();
            _local4 = _local4.add(_local5.scale((Math.random() * _local2)));
            _local4 = _local4.add(_local6.scale((((Math.random() - 0.5) * 2) * _local3)));
            return (_local4);
        }
        public function findCrowdPosMayor():Vector3{
            var _local1:Vector3 = this.getHotspot();
            _local1.x = (_local1.x - 2);
            _local1.y = (_local1.y + (-1 + (((Math.random() * 2) - 1) * 1.5)));
            return (_local1);
        }
        public function findCrowdPosCeremony():Vector3{
            var _local1:Vector3 = new Vector3(0, 0, 1);
            var _local2:Vector3 = getPosition();
            var _local3:Vector3 = this.sidewalkSideToNormalVector(this.getHotspotSidewalkSide());
            var _local4:Vector3 = _local3.cross(_local1).normalize();
            var _local5:Number = getSize().x;
            var _local6:Number = getSize().y;
            _local2.x = (_local2.x + (_local5 / 2));
            _local2.y = (_local2.y + (_local6 / 2));
            var _local7:Number = Math.random();
            if (_local7 <= 0.5){
                _local2.x = (_local2.x - ((_local5 / 2) + Math.random()));
                _local2.y = (_local2.y + ((Math.random() * 2) - 1));
            } else {
                _local2.y = (_local2.y - ((_local6 / 2) + Math.random()));
                _local2.x = (_local2.x + ((Math.random() * 2) - 1));
            };
            return (_local2);
        }
        public function isBeingDragged():Boolean{
            return (this.m_isDragged);
        }
        public function get isHighlightable():Boolean{
            return ((this.isNeedingRoad) ? ((this.m_isHighlightable) && (Global.world.isEditMode)) : this.m_isHighlightable);
        }
        public function showActionBar():Boolean{
            return (true);
        }
        public function deferProgressBarToNPC():Boolean{
            return (true);
        }
        override protected function updateActionBarPosition():void{
            var _local1:Point;
            if (((m_actionBar) && (m_actionBar.visible))){
                if (!this.m_content){
                    return (super.updateActionBarPosition());
                };
                _local1 = this.tileScreenPosition;
                _local1.y = (_local1.y - m_overrideActionBarY);
                _local1 = IsoMath.viewportToStage(_local1);
                _local1.y = (_local1.y - this.m_content.height);
                m_actionBar.x = ((_local1.x - (ACTIONBAR_WIDTH / 2)) + m_actionBarOffsetX);
                m_actionBar.y = ((_local1.y - ACTIONBAR_HEIGHT) + m_actionBarOffsetY);
            };
        }
        public function getPopulationYield():int{
            if (this.m_currentPopulation == 0){
                this.m_currentPopulation = m_item.populationBase;
            };
            return (this.m_currentPopulation);
        }
        public function addPopulation(_arg1:int):void{
            if (this.m_currentPopulation == 0){
                this.m_currentPopulation = m_item.populationBase;
            };
            this.m_currentPopulation = (this.getPopulationYield() + _arg1);
            if (this.m_currentPopulation > m_item.populationMax){
                this.m_currentPopulation = m_item.populationMax;
            };
            if (this.m_currentPopulation < m_item.populationBase){
                this.m_currentPopulation = m_item.populationBase;
            };
        }
        public function getPopulationCapYield():int{
            return (m_item.populationCapYield);
        }
        protected function friendVisitRepGain():int{
            return (0);
        }
        public function initFriendData(_arg1:String):void{
        }
        override public function onPlayAction():void{
            var _local1:Boolean;
            var _local2:Number;
            var _local3:Array;
            var _local4:int;
            super.onPlayAction();
            if (m_item.clickSound != null){
                _local1 = false;
                if (this.m_SoundClickPlayed == -1){
                    _local1 = true;
                };
                if (!_local1){
                    _local2 = (GlobalEngine.getTimer() - this.m_SoundClickPlayed);
                    if (_local2 > this.m_SoundClickDelayTime){
                        _local1 = true;
                    };
                };
                if (_local1){
                    _local3 = m_item.clickSound.split(":");
                    Sounds.playSoundFromArray(_local3);
                    this.m_SoundClickPlayed = GlobalEngine.getTimer();
                    _local4 = Math.round(Utilities.randBetween(Global.gameSettings.getInt("clickSoundMinReplayWait"), Global.gameSettings.getInt("clickSoundMaxReplayWait")));
                    this.m_SoundClickDelayTime = (_local4 * 1000);
                };
            };
        }
        public function getPickupAction():Class{
            return (null);
        }
        public function getPickupFunction():Function{
            return (null);
        }
        public function getActionText():String{
            return ("");
        }
        protected function makeDoobers(_arg1:Number=1):Array{
            return (null);
        }
        public function spawnDoobers(_arg1:Boolean=false):void{
            GlobalEngine.log("Doobers", ("MapResource.spawnDoobers() on " + this.getItemName()));
            Global.world.dooberManager.createBatchDoobers(this.m_doobersArray, m_item, m_position.x, m_position.y, _arg1);
        }
        public function set doobersArray(_arg1:Array):void{
            this.m_doobersArray = _arg1;
        }
        public function set secureRandsArray(_arg1:Array):void{
            this.m_secureRands = _arg1;
        }
        protected function processBaseDoobers(_arg1:Item, _arg2:Array):Dictionary{
            var _local5:Array;
            var _local6:String;
            var _local7:Item;
            var _local3:Array = Global.player.processRandomModifiers(_arg1, this, true, _arg2);
            var _local4:Dictionary = new Dictionary();
            for each (_local5 in _local3) {
                if (_local5[0] == Global.gameSettings.getDooberFromType(Doober.DOOBER_COIN, _local5[1])){
                    _local4[Doober.DOOBER_COIN] = _local5[1];
                } else {
                    if (_local5[0] == Global.gameSettings.getDooberFromType(Doober.DOOBER_XP, _local5[1])){
                        _local4[Doober.DOOBER_XP] = _local5[1];
                    } else {
                        if (_local5[0] == Global.gameSettings.getDooberFromType(Doober.DOOBER_ENERGY, _local5[1])){
                            _local4[Doober.DOOBER_ENERGY] = _local5[1];
                        } else {
                            if (_local5[0] == Global.gameSettings.getDooberFromType("food", _local5[1])){
                                _local4["food"] = _local5[1];
                            } else {
                                if (_local5[0] == Global.gameSettings.getDooberFromType(Doober.DOOBER_GOODS, _local5[1])){
                                    _local4[Doober.DOOBER_GOODS] = _local5[1];
                                } else {
                                    _local6 = _local5[0];
                                    _local7 = Global.gameSettings.getItemByName(_local6);
                                    if (_local7.type == Doober.DOOBER_COLLECTABLE){
                                        _local4[Doober.DOOBER_COLLECTABLE] = _local6;
                                    } else {
                                        _local4[Doober.DOOBER_ITEM] = _local6;
                                    };
                                };
                            };
                        };
                    };
                };
            };
            return (_local4);
        }
        protected function enterMoveMode():void{
            this.setActive(false);
            Global.world.addGameMode(new GMEdit());
            Global.world.addGameMode(new GMObjectMove(this, null, null, Constants.INDEX_NONE, true), false);
        }
        public function isPlacedObjectNonBuilding():Boolean{
            return (false);
        }
        public function GetNoMoveMessage():String{
            return (ZLoc.t("Main", "NoMove"));
        }
        public function getProgressBarOffset():Point{
            return (new Point(0, 0));
        }
        public function getConstructionNPCOffset():Point{
            return (new Point(0, 0));
        }
        public function getProgressBarStartFunction():Function{
            return (null);
        }
        public function getProgressBarEndFunction():Function{
            return (null);
        }
        public function getProgressBarCancelFunction():Function{
            return (null);
        }
        public function get stagePickEffect():StagePickEffect{
            return (this.m_stagePickEffect);
        }
        public function set stagePickEffect(_arg1:StagePickEffect):void{
            if (_arg1 != this.m_stagePickEffect){
                this.removeStagePickEffect();
                this.m_stagePickEffect = _arg1;
            };
        }
        protected function createStagePickEffect():void{
        }
        public function setShowUpgradeArrow(_arg1:Boolean):void{
            this.m_showUpgradeArrow = _arg1;
        }
        public function getShowUpgradeArrow():Boolean{
            return (this.m_showUpgradeArrow);
        }
        public function removeStagePickEffect():void{
            if (this.m_stagePickEffect){
                this.m_stagePickEffect.stopFloat();
                this.m_stagePickEffect.cleanUp();
                this.m_stagePickEffect = null;
            };
        }
        public function getActionTargetName():String{
            var _local1 = "";
            if (m_item){
                _local1 = m_item.name;
            };
            return (_local1);
        }
        public function getVisitReplayEquivalentActionString():String{
            return ("");
        }
        public function warnForStorage():Boolean{
            return (false);
        }
        public function warnForStorageMessage():String{
            return (ZLoc.t("Dialogs", "warehouseWarning", {itemName:this.getItem().localizedName}));
        }
        public function prepareForStorage():void{
            this.m_itemImage = null;
            m_displayObject = null;
        }
        public function restoreFromStorage():void{
            this.trackAction(TrackedActionType.RESTORE);
        }
        public function addSupply(_arg1:String, _arg2:int):Boolean{
            if (!this.m_supplyStorage){
                this.m_supplyStorage = new SupplyStorage();
            };
            var _local3:Object = this.getSupplyCapacities();
            this.m_supplyStorage.setCapacities(_local3);
            var _local4:Boolean = this.m_supplyStorage.add(_arg1, _arg2);
            return (_local4);
        }
        public function removeSupply(_arg1:String, _arg2:int):Boolean{
            var _local3:Boolean;
            if (this.m_supplyStorage){
                _local3 = this.m_supplyStorage.remove(_arg1, _arg2);
                if (this.m_supplyStorage.getTotalCount() == 0){
                    this.m_supplyStorage = null;
                };
            };
            return (_local3);
        }
        public function clearSupply():Boolean{
            this.m_supplyStorage = null;
            return (true);
        }
        public function getSupply(_arg1:String):int{
            var _local2:int;
            if (this.m_supplyStorage){
                _local2 = this.m_supplyStorage.getCount(_arg1);
            };
            return (_local2);
        }
        protected function getSupplyCapacities():Object{
            return ({});
        }
        public function isUpgradePossible():Boolean{
            return (((((!((m_item.upgrade == null))) && (m_item.upgrade.isValid()))) && (m_item.upgrade.isUpgradePossible(this))));
        }
        public function canCountUpgradeActions():Boolean{
            var _local1:Item = this.getItem();
            return (((_local1) && (_local1.canCountUpgradeActions())));
        }
        public function canShowUpgradeToolTips():Boolean{
            return (((this.canCountUpgradeActions()) || (this.canShowAlternativeUpgradeToolTip())));
        }
        public function canShowAlternativeUpgradeToolTip():Boolean{
            var _local1:Item = this.getItem();
            return (((_local1) && ((_local1.level > 1))));
        }
        public function showUpgradeProgressFloaterText(_arg1:uint=0xFFFFFF):void{
            var _local2:Number;
            var _local3:Number;
            if (this.canCountUpgradeActions()){
                _local2 = Number(this.getItem().upgrade.requirements.getRequirementValue(Requirements.REQUIREMENT_UPGRADE_ACTIONS));
                _local3 = Math.min(this.upgradeActions.getTotal(), _local2);
                if (_local3 < _local2){
                    this.displayStatus(ZLoc.t("Main", "LevelProgress", {
                        amount:_local3,
                        total:_local2
                    }), "", _arg1);
                } else {
                    this.displayStatus(ZLoc.t("Main", "UpgradeReady"), "", _arg1);
                };
            };
        }
        public function upgradeBuildingIfPossible(_arg1:Boolean=true, _arg2:Transaction=null, _arg3:Boolean=true):void{
            if (!this.isUpgradePossible()){
                return;
            };
            if (_arg2){
                GameTransactionManager.addTransaction(_arg2);
            } else {
                GameTransactionManager.addTransaction(new TUpgradeBuilding(this));
            };
            var _local4:Item = Global.gameSettings.getItemByName(m_item.upgrade.newItemName);
            this.onUpgrade(m_item, _local4, _arg3);
            this.doUpgradeAnimations(this.m_defaultUpgradeFinish, _arg1);
            Global.ui.dispatchEvent(new GenericObjectEvent(GenericObjectEvent.BUILDING_UPGRADE, this));
        }
        public function doUpgradeAnimations(_arg1:Function=null, _arg2:Boolean=true):void{
            this.actionQueue.removeAllStates();
            this.actionQueue.addActions(new ActionProgressBar(null, this, ZLoc.t("Main", "Upgrading")), new ActionFn(this, this.updateArrow));
            if (_arg1 != null){
                this.actionQueue.addActions(new ActionFn(this, _arg1));
            };
            if (_arg2){
                Sounds.playFromSet(Sounds.SET_BUILDING_CONSTRUCTION);
            };
        }
        public function checkPlacementRequirements(_arg1:int, _arg2:int):Boolean{
            var _local6:int;
            var _local3:String = m_item.placeableOn;
            if (_local3 == null){
                _local3 = MapResource.PLACE_ON_LAND;
            };
            var _local4:Vector3 = getSize();
            var _local5:Boolean;
            switch (_local3){
                case MapResource.PLACE_ON_WATER:
                    _local5 = Global.world.citySim.waterManager.positionValidShipOnWater(new Rectangle(_arg1, _arg2, _local4.x, _local4.y));
                    break;
                case MapResource.PLACE_ON_LAND_AND_WATER:
                    _local5 = Global.world.citySim.waterManager.positionValidOnLandAndWater(new Rectangle(_arg1, _arg2, _local4.x, _local4.y), 1, 5);
                    break;
                case MapResource.PLACE_ON_LAND:
                default:
                    if (_local3 == MapResource.PLACE_ON_ROAD_OR_NEARROAD){
                        _local6 = getItem().xml.@mustBeAtRoad;
                        if (_local6 > 0){
                            if (false == this.isAdjacentToAnyRoad){
                                return (false);
                            };
                        };
                    };
                    _local5 = Global.world.citySim.waterManager.positionOnValidLand(new Rectangle(_arg1, _arg2, _local4.x, _local4.y));
            };
            return (_local5);
        }
        public function updateStagePickEffect():void{
            this.updateArrow();
        }
        public function onUpgrade(_arg1:Item, _arg2:Item, _arg3:Boolean=true):void{
            setItem(_arg2);
            this.setState(this.getState());
        }
        public function isNotAtRoad():Boolean{
            var _local1:int = getItem().xml.@mustBeAtRoad;
            return (((_local1) && ((false == this.isAdjacentToAnyRoad))));
        }
        protected function grantUpgradeRewards():Array{
            var _local2:int;
            var _local1:Array = new Array();
            if (((!((m_item.upgrade == null))) && (!((m_item.upgrade.rewards == null))))){
                if (m_item.upgrade.rewards["coin"]){
                    _local1.push(new Array(Global.gameSettings.getDooberFromType(Doober.DOOBER_COIN, m_item.upgrade.rewards["coin"]), m_item.upgrade.rewards["coin"]));
                };
                if (m_item.upgrade.rewards["xp"]){
                    _local1.push(new Array(Global.gameSettings.getDooberFromType(Doober.DOOBER_XP, m_item.upgrade.rewards["xp"]), m_item.upgrade.rewards["xp"]));
                };
                if (m_item.upgrade.rewards["energy"]){
                    _local1.push(new Array(Global.gameSettings.getDooberFromType(Doober.DOOBER_ENERGY, m_item.upgrade.rewards["energy"]), m_item.upgrade.rewards["energy"]));
                };
                if (m_item.upgrade.rewards["goods"]){
                    _local1.push(new Array(Global.gameSettings.getDooberFromType(Doober.DOOBER_GOODS, m_item.upgrade.rewards["goods"]), m_item.upgrade.rewards["goods"]));
                };
                if (m_item.upgrade.rewards["collectable"]){
                    _local1.push(new Array(m_item.upgrade.rewards["collectable"], 1));
                };
            };
            return (_local1);
        }
        public function getGhostImage():ItemImageInstance{
            return (this.getCurrentImage());
        }
        public function notifyUserForExpansionsOnPlace(_arg1:Rectangle):void{
        }
        public function getCrewPositionName(_arg1:String):String{
            var _local5:int;
            var _local2 = "";
            var _local3:Vector.<String> = this.getCrewPositionNames();
            var _local4:Crew = Global.crews.getCrewByObject(this);
            if (_local4){
                _local5 = 0;
                while (_local5 < _local4.list.length) {
                    if ((((_local4.list[_local5] == _arg1)) && ((_local3.length > _local5)))){
                        _local2 = _local3[_local5];
                        break;
                    };
                    _local5++;
                };
            };
            return (_local2);
        }
        public function getCrewPositionNames():Vector.<String>{
            var _local2:XMLList;
            var _local3:XML;
            var _local4:String;
            var _local5:Number;
            var _local6:String;
            var _local7:int;
            var _local1:Vector.<String> = new Vector.<String>();
            if (m_item){
                _local2 = m_item.getCurrentCrewGateXML(this);
                if (((_local2) && ((_local2.length() > 0)))){
                    for each (_local3 in _local2["key"]["member"]) {
                        _local4 = _local3.@name;
                        _local5 = _local3.@amount;
                        _local6 = ZLoc.t("Items", _local4);
                        _local7 = 0;
                        while (_local7 < _local5) {
                            _local1.push(_local6);
                            _local7++;
                        };
                    };
                };
            };
            return (_local1);
        }

    }
}//package Classes 
